package com.hh.test.design.filter;

import java.util.ArrayList;
import java.util.List;

public class Criteria {

	List<Filter> list = new ArrayList<Filter>();

	Criteria filter(Filter filter) {
		list.add(filter);
		return this;
	}

	public List<Person> filter(List<Person> persons) {
		for (Filter filter : list) {
			persons = filter.filter(persons);
		}
		return persons;
	}

	public static void main(String[] args) {
		List<Person> persons = new ArrayList<>();
		persons.add(new Person(10, "M", "name1"));
		persons.add(new Person(60, "F", "name2"));
		persons.add(new Person(40, "F", "name3"));
		persons.add(new Person(45, "F", "name4"));
		persons.add(new Person(45, "M", "name5"));
		Criteria criteria = new Criteria().filter(new SexFilter("F")).filter(new AgeFilter(18, 55));
		List<Person> ps = criteria.filter(persons);
		for (Person p : ps) {
			System.out.println(p);
		}
	}
}
